package com.ssy.lingxi.enhance.handler.async;

import com.ssy.lingxi.report.api.feign.ReportControllerFeign;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 异步服务 - 报表
 * @author fhj
 * @date 2020/11/20
 * @version 2.0.0
 */
@Slf4j
@Component
public class ReportAsyncService {

    @Resource
    private ReportControllerFeign reportControllerFeign;

    /**
     * 新增操作通知
     * @param memberId 会员ID
     * @param roleId 角色ID
     * @param dataSource 数据源
     * @param increaseStatus 增加的待办
     * @param increaseNum 增加的数量
     * @param reduceStatus 减少的待办
     * @param reduceNum 减少的数量
     */
    @Async
    public void addOperateNotice(Long memberId, Long roleId, Integer dataSource, Integer increaseStatus, Long increaseNum, Integer reduceStatus, Long reduceNum) {
        try {
            OperateNoticeVO noticeVO = new OperateNoticeVO();
            noticeVO.setMemberId(memberId);
            noticeVO.setRoleId(roleId);
            noticeVO.setDataSource(dataSource);

            //增加的待办与数量
            if(increaseStatus != null) {
                noticeVO.setIncreaseOperateType(increaseStatus);
                noticeVO.setIncreaseCount(increaseNum);
            }

            //减少的待办与数量
            if(reduceStatus != null) {
                noticeVO.setReduceOperateType(reduceStatus);
                noticeVO.setReduceCount(reduceNum);
            }

            reportControllerFeign.addOperateNotice(noticeVO);
        } catch (Exception e) {
            log.info("调用报表服务新增操作通知接口失败：{}", e.getMessage());
        }
    }

    /**
     * 批量新增操作通知
     * @param noticeVOList OperateNoticeVO集合
     */
    @Async
    public void addOperateNoticeList(List<OperateNoticeVO> noticeVOList) {
        //调用报表服务 -> 新增操作通知（如果调用过程出现异常, 无需回滚, 直接catch打印日志正常返回。）
        try {
            reportControllerFeign.addOperateNoticeList(noticeVOList);
        } catch (Exception e) {
            log.info("调用报表服务批量新增操作通知接口失败：{}", e.getMessage());
        }
    }
}
